package com.ruoyi.trainingManagement.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.trainingManagement.domain.FirstLevelDiscipline;
import com.ruoyi.trainingManagement.service.IFirstLevelDisciplineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 一级学科目录Controller
 * 
 * @author ruoyi
 * @date 2025-07-23
 */
@RestController
@RequestMapping("/trainingManagement/discipline")
public class FirstLevelDisciplineController extends BaseController
{
    @Autowired
    private IFirstLevelDisciplineService firstLevelDisciplineService;

    /**
     * 查询一级学科目录列表
     */
    //@PreAuthorize("@ss.hasPermi('trainingManagement:discipline:list')")
    @GetMapping("/list")
    public TableDataInfo list(FirstLevelDiscipline firstLevelDiscipline)
    {
        startPage();
        List<FirstLevelDiscipline> list = firstLevelDisciplineService.selectFirstLevelDisciplineList(firstLevelDiscipline);
        return getDataTable(list);
    }

    /**
     * 导出一级学科目录列表
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:discipline:export')")
    @Log(title = "一级学科目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FirstLevelDiscipline firstLevelDiscipline)
    {
        List<FirstLevelDiscipline> list = firstLevelDisciplineService.selectFirstLevelDisciplineList(firstLevelDiscipline);
        ExcelUtil<FirstLevelDiscipline> util = new ExcelUtil<FirstLevelDiscipline>(FirstLevelDiscipline.class);
        util.exportExcel(response, list, "一级学科目录数据");
    }

    /**
     * 获取一级学科目录详细信息
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:discipline:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(firstLevelDisciplineService.selectFirstLevelDisciplineById(id));
    }

    /**
     * 新增一级学科目录
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:discipline:add')")
    @Log(title = "一级学科目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FirstLevelDiscipline firstLevelDiscipline)
    {
        return toAjax(firstLevelDisciplineService.insertFirstLevelDiscipline(firstLevelDiscipline));
    }

    /**
     * 修改一级学科目录
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:discipline:edit')")
    @Log(title = "一级学科目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FirstLevelDiscipline firstLevelDiscipline)
    {
        return toAjax(firstLevelDisciplineService.updateFirstLevelDiscipline(firstLevelDiscipline));
    }

    /**
     * 删除一级学科目录
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:discipline:remove')")
    @Log(title = "一级学科目录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(firstLevelDisciplineService.deleteFirstLevelDisciplineByIds(ids));
    }
}
